package com.hyk.aop;

import javax.annotation.Resource;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MarryCompany implements InvocationHandler {

    @Resource
    private Object marry;

    public MarryCompany(Object marry){
        this.marry = marry;
    }

    public Object getProxy(){
        return Proxy.newProxyInstance(
                this.getClass().getClassLoader(),
                marry.getClass().getInterfaces(),
                this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("before");
        method.invoke(marry,args);
        System.out.println("after");

        return null;
    }
}
